<?php 
  require_once("../../includes/config.php"); 
  
  $sql = 'SELECT * FROM clients where owner_id = ?';

  $binds = array();
  
  $binds['owner_id'] = $_SESSION['user_id'];

  if(isset($_GET['ident']) || isset($_GET['name'])) 
  {
    if(!empty($_GET['ident']) )
    {
      if(!empty($binds))
        $and = " and ";
      else
        $and = " ";
             
      $binds['id'] = $_GET['ident'];
      $sql .= $and."identification_number  = ?";
    }
    if(!empty($_GET['name']) )
    {
      if(!empty($binds))
        $and = " and ";
      else
        $and = " ";
             
      $binds['id'] = $_GET['name'];
      $sql .= $and."name  = ?";
    }
    $clients = query($sql,$binds);
    if(!empty($clients))
    {
      $clients = json_encode($clients);
      echo $clients;
    }
    else
      echo 0;
  } 
  else
  {
    $clients = query($sql,$binds);
    if(isset($_GET['f']))
      $f = 1;
    else
      $f = 0;
    
    renderWithoutHeader("Customers/choose_client.php", array("clients"=>$clients,"flag"=>$f));
  }
?>